package model;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import connect.Connect;

public class StudentDAO {
	public Student find(String mssv) {
		Student result = new Student();

		Connection con = new Connect().getConnection();
		try {
			Statement state = con.createStatement();
			String sql = "select name, agrade from student where mssv='" + mssv
					+ "'";

			ResultSet rs = state.executeQuery(sql);
			while (rs.next()) {
				result.setMssv(mssv);
				result.setName(rs.getString(1));
				result.setaGrade(rs.getDouble(2));

				break;
			}

			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return result;
	}

	public List<String> getAllMSSV() {
		List<String> result = new ArrayList<String>();

		try {
			Connection con = new Connect().getConnection();
			Statement state = con.createStatement();
			String sql = "select mssv from student";

			ResultSet rs = state.executeQuery(sql);
			while (rs.next()) {
				result.add(rs.getString(1));
			}

			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return result;
	}

}
